{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#  表达式\n",
    "- 由一个或几个数字或者变量和运算符组合成的一行代码\n",
    "- 通常会返回一个结果\n",
    "\n",
    "# 运算符\n",
    "- 由一个以上的值经过变化得到新值的过程叫运算\n",
    "- 用于运算的符号叫运算符\n",
    "- python 没有自增 自减预算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "100\n",
      "2.25\n",
      "2\n",
      "2\n",
      "6561\n",
      "10\n"
     ]
    }
   ],
   "source": [
    "# + - * /\n",
    "a = 9 +2 -1\n",
    "print(a)\n",
    "\n",
    "a = 10*10\n",
    "print(a)\n",
    "\n",
    "# python2 中取整。 python3 是数学运算上的除\n",
    "a= 9/4\n",
    "print(a)\n",
    "\n",
    "# % 取余数\n",
    "# 两个数相除应有 商数 和余数， % 只取余数\n",
    "a = 12%10\n",
    "print(a)\n",
    "\n",
    "# // 取商 预算，地板除\n",
    "a = 9//4\n",
    "print(a)\n",
    "\n",
    "# ** 幂预算\n",
    "a = 9**4\n",
    "print(a)\n",
    "\n",
    "# 测试自增\n",
    "a = 10\n",
    "print(a)\n",
    "# a--  # 报错， ++ 同样，报语法错误\n",
    "# print(a)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 比较运算符\n",
    " - 2个变量或者值进行比较的运算符\n",
    " - 比较的结果是布尔值，即 True/False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "# == 等于\n",
    "a = 3 ** 4\n",
    "b = a==80\n",
    "print(b)\n",
    "\n",
    "# != 不等于\n",
    "print(100!=20)\n",
    "\n",
    "print(100>20)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 赋值运算符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 0\n",
      "7\n"
     ]
    }
   ],
   "source": [
    "# =  赋值\n",
    "a =10 \n",
    "c =a = 0\n",
    "print(c,a)\n",
    "\n",
    "a = 0\n",
    "a += 7\n",
    "print(a)\n",
    "# 所有数学运算符都有缩写形式\n",
    "# -=，×=，/=，//=, %=,**= 都是缩写形式"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 逻辑运算符\n",
    "- 对布尔值进行计算的符号\n",
    "- and 逻辑与\n",
    "- or 逻辑或\n",
    "- not 逻辑非\n",
    "- Python中逻辑运算没有异或运算\n",
    "- 运算规则：\n",
    "    - and 看做乘法，or看做加法\n",
    "    - True看做1， False看做0\n",
    "    - 逻辑运算可转换成数学运算\n",
    "    - 最后结果如果为0 即False, 否则为True\n",
    "- 逻辑预算的短路问题\n",
    "    - 逻辑预算中，一旦能够确定整个式子未来的值，则不再进行计算，直接返回"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "a = True\n",
    "b = False\n",
    "c = True\n",
    "\n",
    "d = a and b or c\n",
    "print(d)\n",
    "\n",
    "d = a or b and c\n",
    "print(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 逻辑运算 短路的demo\n",
    "\n",
    "\n",
    "a = True or xxxx"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 成员运算符\n",
    "- 用来检测某一个变量是否是另外一个变量的成员\n",
    "- in\n",
    "- not in"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "# DEMO\n",
    "l = [1,3,5,6]\n",
    "a =7\n",
    "b = a in l\n",
    "print(b)\n",
    "\n",
    "a = 5\n",
    "b = a in l\n",
    "print(b)\n",
    "print(a not in l)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 运算符的优先级问题\n",
    "- 永远记住，括号具有最高优先级\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
